package com.linkme2night.controller;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;

import com.linkme2night.model.ClubberDAO;
import com.linkme2night.model.Comment;
import com.linkme2night.model.CommentDAO;
import com.linkme2night.model.Rate;
import com.linkme2night.model.RateDAO;
import com.linkme2night.model.VenueDAO;
import com.linkme2night.view.interactwithvenue.InteractWithVenueActivity;

public class InteractWithVenueController {

	private CommentDAO commentDAO;
	private ClubberDAO  cluberDAO;
	private RateDAO rdao;
	private VenueDAO venue;
	private FrontController fcontroller;
	private  ArrayList<Comment> commentList;

	public void addComment(Comment comment) {

		commentDAO = new CommentDAO();
		commentDAO.add(comment);
	}

	public List<Comment> getComments(int venueID) {

		commentDAO = new CommentDAO();
		return commentDAO.getComments(venueID);
	}

	public List<Comment> getLatestComments(int venueID, int clubberID) {
		commentDAO = new CommentDAO();
		return commentDAO.getLatestComment(venueID, clubberID);

	}
	
	public void setTonightRate(Rate r){
		rdao= new RateDAO();
		rdao.addRate(r);
	}

	public boolean openInteractwithVenue(Context context, int venueID,
			int clubberID) {
		float overallRanking;
		String venueName, venueDescription, venueAddress, venueOpeningHours, venueClosingHours;

		// getting data to open view
		commentDAO = new CommentDAO();
		venue = new VenueDAO();

		commentList = (ArrayList<Comment>) commentDAO.getComments(venueID);

		overallRanking = venue.getOverallRanking(venueID);
		venueName = venue.getName(venueID);
		venueDescription = venue.getDescription(venueID);
		venueAddress = venue.getAddress(venueID);
		venueOpeningHours = venue.getOpeningHours(venueID).toString();
		venueClosingHours = venue.getClosingHours(venueID).toString();

		// dispatching to activity

		Intent intent = new Intent();
		// preparing data to send
		intent.putExtra("clubberID", clubberID);
		intent.putExtra("venueID", venueID);
		intent.putExtra("overallRanking", overallRanking);
		intent.putExtra("venueName", venueName);
		intent.putExtra("venueDescription", venueDescription);
		intent.putExtra("venueAddress", venueAddress);
		intent.putExtra("venueOpeningHours", venueOpeningHours);
		intent.putExtra("venueClosingHours", venueClosingHours);
		intent.putExtra("commentList", commentList);

		// start Activity
		intent.setClass(context, InteractWithVenueActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent);
		return true;
	}

	public String getClubberName(int clubberID) {
		cluberDAO= new ClubberDAO();
		
		return null;//cluberDAO.getName(clubberID);
	}

	public void openViewVenueOnMap(Context context, int venueID,
			int clubberID) {
		
		fcontroller.openViewVenueOnMap(context,venueID,clubberID);
		
	}

	

}
